home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 8.0 KB | 283 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Part.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Container.hpp"
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef PROXY_H
- #include "Proxy.h"
- #endif
-
- #ifndef VIEW_H
- #include "View.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfcontainer
- #endif
-
- //========================================================================================
- // Globals
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(CContainerPart, FW_CEmbeddingPart)
- FW_DEFINE_AUTO(CContainerPart)
-
- //========================================================================================
- // class CContainerPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::CContainerPart
- //----------------------------------------------------------------------------------------
-
- CContainerPart::CContainerPart(ODPart* odPart) :
- FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID)
- {
- fPartContent = NULL;
- fMainPresentation = NULL;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::~CContainerPart
- //----------------------------------------------------------------------------------------
-
- CContainerPart::~CContainerPart()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CContainerPart::Initialize(Environment* ev)
- {
- // ----- Call Inherited Initialize -----
- FW_CEmbeddingPart::Initialize(ev);
-
- fDrawingSize.Set(FW_IntToFixed(kDrawingSizeX), FW_IntToFixed(kDrawingSizeY));
-
- // ----- Initialize the menu bar
- // We instantiate a submenu item from the stream so we must
- // prevent it from being deadstripped.
- FW_DO_NOT_DEAD_STRIP(FW_CSubMenuItem);
- GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
-
- // ----- Tokenize -----
- fContainerSelection = FW_NEW(CContainerSelection, (ev, this)); // Attention I don't own the selection the presentation will
-
- fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, fContainerSelection);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::NewPartContent
- //----------------------------------------------------------------------------------------
-
- FW_CContent* CContainerPart::NewPartContent(Environment* ev)
- {
- fPartContent = FW_NEW(CPartContent, (ev, this));
- return fPartContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::AddProxyToPart
- //----------------------------------------------------------------------------------------
-
- void CContainerPart::AddProxyToPart(Environment* ev, CProxy* proxy)
- {
- fPartContent->AddProxy(ev, proxy);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::DetachProxy
- //----------------------------------------------------------------------------------------
- // At the end the embedded frames associated with 'proxy' will be in limbo
-
- void CContainerPart::DetachProxy(Environment* ev, CProxy* proxy)
- {
- fPartContent->RemoveProxy(ev, proxy);
- proxy->DetachEmbeddedFrames(ev); // Set embedded frames to in limbo state
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::DeleteProxy
- //----------------------------------------------------------------------------------------
- // At the end the embedded frames are completly gone
-
- void CContainerPart::DeleteProxy(Environment* ev, CProxy* proxy)
- {
- DetachProxy(ev, proxy);
- delete proxy;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::AttachProxy
- //----------------------------------------------------------------------------------------
- // Put back (for example after Undo) a proxy that has been detached
-
- void CContainerPart::AttachProxy(Environment* ev, CProxy* proxy)
- {
- AddProxyToPart(ev, proxy);
- proxy->AttachEmbeddedFrames(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Boolean result = TRUE;
- ODCommandID commandID = theMenuEvent.GetCommandID(ev);
-
- switch (commandID)
- {
- case kODCommandAbout:
- ::FW_About(ev, this, kAbout);
- break;
- default:
- result = false;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CContainerPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage)
- {
- return FW_NEW(CContainerFrame, (ev, odFrame, presentation, this, kContainerView));
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- if (hasMenuFocus)
- menuBar->EnableCommand(ev, kODCommandSelectAll, fPartContent->CountProxies() > 0);
-
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::WhichProxy
- //----------------------------------------------------------------------------------------
-
- CProxy* CContainerPart::WhichProxy(Environment* ev, FW_CGraphicContext& gc,
- const FW_CPoint& where, FW_Boolean hasToBeSelected) const
- {
- CContentProxyIterator ite(fPartContent);
- for (CProxy* proxy = ite.Last(); ite.IsNotComplete(); proxy = ite.Previous())
- {
- FW_Boolean test = (!hasToBeSelected) || (hasToBeSelected && proxy->IsSelected());
- if (test && proxy->HitTest(ev, gc, where))
- return proxy;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerPart::EmbeddedFrameRemoved
- //----------------------------------------------------------------------------------------
-
- void CContainerPart::EmbeddedFrameRemoved(Environment *ev, FW_MProxy* proxy)
- {
- CProxy* theProxy = (CProxy*)proxy;
-
- FW_CAcquiredODShape updateShape = ::FW_NewODShape(ev);
- theProxy->GetUpdateBox(ev, updateShape);
- theProxy->GetPresentation(ev)->Invalidate(ev, updateShape);
-
- DeleteProxy(ev, theProxy);
- }
-